package com.mjh.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mjh.mapper.FileEntiyMapper;
import com.mjh.pojo.Events;
import com.mjh.mapper.EventsMapper;
import com.mjh.pojo.FileEntiy;
import com.mjh.pojo.vo.EventsVo;
import com.mjh.service.IEventsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 活动 服务实现类
 * </p>
 *
 * @author MJH
 * @since 2021-12-03
 */
@Service
public class EventsServiceImpl extends ServiceImpl<EventsMapper, Events> implements IEventsService {

    @Autowired
    EventsMapper eventsMapper;

    @Autowired
    FileEntiyMapper fileEntiyMapper;

    @Override
    public Page<Events> eventstop(Page<Events> page) {
        return eventsMapper.eventstop(page);
    }


    /**
     * 查询活动详情
     * @return
     */
    public EventsVo queryEventsByid(Integer id){
        QueryWrapper<Events> wrapper = new QueryWrapper<>();
        wrapper.select("f_ggtp","title","wssbkssj","wssbjssj","content","status","sbxz","annex")
                .eq("id",id);
        Events events = eventsMapper.selectOne(wrapper);
        //获取附件编号
        String annex = events.getAnnex();
        String[] split = annex.split(",");  //id
        ArrayList<Integer> list = new ArrayList<>();
        for (String s : split) {
            Integer fileId=Integer.parseInt(s);
            list.add(fileId);
        }


        //附件文件信息集合
        List<FileEntiy> fileEntiys = fileEntiyMapper.selectBatchIds(list);

        EventsVo eventsVo = BeanUtil.copyProperties(events, EventsVo.class, "");
        eventsVo.setAnnexFile(fileEntiys);

        return  eventsVo;
    }
}
